﻿'Option Explicit On
'Option Strict On
Imports DBUtilitiesLibrary
Imports DARSClassLibrary
Public Class AdvisorViewStudentCourses
    Inherits System.Web.UI.Page
    Dim pxy As New DO_NOT_MOVE_ME_FROM_THIS_PROJECT.DARSWebservice
    Dim db As New DARSDBConnection
    Dim RecordDS As DataSet
    Dim InfoDS As DataSet

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Check if user is logged in
        If Session("CurrentUser") Is Nothing Then
            Response.Redirect("NotLoggedIn.aspx")
            Exit Sub
        Else
            Dim stuID As String = CType(Session("CurrentUser"), String)

            lblFirstName.Text = CStr(InfoDS.Tables(0).Rows(0)("FirstName")) & " , "
            lblLastName.Text = CStr(InfoDS.Tables(0).Rows(0)("LastName"))
            lblFName.Visible = True
            lblLName.Visible = True
            RecordDS = pxy.getStudentCourseRecord(stuID)
            Session("ds") = RecordDS
            gvStuInfo.DataSource = RecordDS
            gvStuInfo.DataBind()


            gvStuInfo.Visible = False
            lblErr.Text = ""
            lblFirstName.Text = ""
            lblLastName.Text = ""
            lblFName.Visible = False
            lblLName.Visible = False
        End If
    End Sub


    'Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click


    '    Dim stuID As String
    '    stuID = txtStuID.Text.Trim


    '    If Not StuIDValidate(stuID) = "" Then
    '        lblErr.Text = StuIDValidate(stuID)
    '        Exit Sub
    '    Else
    '        Try
    '            InfoDS = pxy.getStudentPersonalInfo(stuID)
    '            If InfoDS.Tables(0).Rows.Count = 0 Then
    '                lblFirstName.Text = "Student Not Found"
    '                gvStuInfo.Visible = False
    '            Else
    '                lblFirstName.Text = CStr(InfoDS.Tables(0).Rows(0)("FirstName")) & " , "
    '                lblLastName.Text = CStr(InfoDS.Tables(0).Rows(0)("LastName"))
    '                lblFName.Visible = True
    '                lblLName.Visible = True
    '                RecordDS = pxy.getStudentCourseRecord(stuID)
    '                Session("ds") = RecordDS
    '                'If ds.Tables(0).Rows.Count < 1 Then
    '                '    lblErr.Visible = True
    '                '    gvStuInfo.Visible = False
    '                '    lblErr.Text = "No record found"
    '                '    Exit Sub
    '                'Else
    '                gvStuInfo.Visible = True
    '                lblErr.Visible = False
    '                gvStuInfo.DataSource = RecordDS
    '                gvStuInfo.DataBind()
    '                ' gvStuInfo.EmptyDataText = "No record found"
    '            End If
    '        Catch ex As Exception
    '            lblErr.Text = "An error occured. Please try again!"
    '            lblFirstName.Visible = False
    '            lblFName.Visible = False
    '            lblLastName.Visible = False
    '            lblLName.Visible = False
    '        End Try

    '    End If
    'End Sub
    'Protected Function StuIDValidate(ByVal txt As String) As String


    '    If txt = "" Then
    '        Return "StudentID cannot be empty"
    '    ElseIf Not IsNumeric(txt) OrElse txt.Contains(".") Then
    '        Return "StudentID Must be all digits"
    '    Else
    '        Return ""
    '    End If
    'End Function


    'Private Sub gvStuInfo_PreRender(sender As Object, e As System.EventArgs) Handles gvStuInfo.PreRender
    '    'Dim gv As GridView = CType(sender, GridView)
    '    'Dim gvr As GridViewRow = CType(gv.BottomPagerRow, GridViewRow)
    '    'If gvr IsNot Nothing Then
    '    '    gvr.Visible = True
    '    'End If
    'End Sub

    Private Sub gvStuInfo_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvStuInfo.PageIndexChanging
        Dim pindex As Integer = e.NewPageIndex
        gvStuInfo.DataSource = CType(Session("ds"), DataSet)
        gvStuInfo.PageIndex = pindex
        gvStuInfo.DataBind()
    End Sub
    Private Sub gvStuInfo_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvStuInfo.RowDataBound
        If e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(0).Text = "Page " & (gvStuInfo.PageIndex + 1) & " of " & gvStuInfo.PageCount
        End If
    End Sub
End Class
